package day10;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

public class Apple {
    //省略getter和setter
    private String type;
    private String color;
    private double weight;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Apple apple = (Apple) o;
        return Double.compare(weight, apple.weight) == 0 && Objects.equals(type, apple.type) && Objects.equals(color, apple.color);
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, color, weight);
    }

    public Apple(String type, String color, double weight) {
        this.type = type;
        this.color = color;
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "type='" + type + '\'' +
                ", color='" + color + '\'' +
                ", weight=" + weight +
                '}';
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public Object getName() {
        return null;
    }


    public static List<Apple>  filter(List<Apple> datas, Predicate<Apple> filter){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(filter.test(apple)){
                result.add(apple);
            }
        }
        return result;
    }


    public static <T, R> List<R> map(List<T> list, java.util.function.Function<T, R> mapper) {
        List<R> result = new ArrayList<>();
        for (T item : list) {
            result.add(mapper.apply(item));
        }
        return result;
    }
}
